package com.college.controller.resource;


import com.college.common.pojo.ao.CampusInformation;
import com.college.common.pojo.ao.CampusInformationType;
import com.college.common.pojo.dto.resource.*;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.service.CampusInformationService;
import com.college.resource.service.CampusInformationTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 校园资讯分类 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/campus-information-type")
@Api(tags = "校园资讯分类")
@Slf4j
public class CampusInformationTypeController {

    @Autowired
    private CampusInformationTypeService campusInformationTypeService;

    @ApiOperation(value = "查询校园资讯分类列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<CampusInformationType>> queryList(QueryCampusInformationTypeDTO queryCampusInformationTypeDTO) {
        return CommonResult.success(campusInformationTypeService.queryList(queryCampusInformationTypeDTO));
    }

    @ApiOperation(value = "查询校园资讯分类列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<CampusInformationType>> queryListPage(QueryCampusInformationTypeDTO queryCampusInformationTypeDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(campusInformationTypeService.queryListPage(queryCampusInformationTypeDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增校园资讯分类")
    @PostMapping(value = "/add")
    public CommonResult<String> addCampusInformationType(@RequestBody AddCampusInformationTypeDTO addCampusInformationTypeDTO) {
        return campusInformationTypeService.addCampusInformationType(addCampusInformationTypeDTO);
    }

    @ApiOperation(value = "删除校园资讯分类")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteCampusInformationType(@PathVariable Long id) {
        return CommonResult.success(campusInformationTypeService.removeById(id));
    }

    @ApiOperation(value = "批量删除校园资讯分类")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteCampusInformationType(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(campusInformationTypeService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新校园资讯分类")
    @PutMapping(value = "/update")
    public CommonResult<String> updateCampusInformationType(@RequestBody UpdateCampusInformationTypeDTO updateCampusInformationTypeDTO) {
        return campusInformationTypeService.updateCampusInformationType(updateCampusInformationTypeDTO);
    }
}

